/*
 * Buffer.cpp
 *
 *  Created on: Nov 9, 2012
 *      Author: root
 */

#include "Buffer.h"

namespace zeus
{

Buffer::Buffer()
{
	_read = 0;
	_write = 0;
}

Buffer::~Buffer()
{
}

void Buffer::swap(Buffer & rhs)
{
	_data.swap(rhs._data);

	std::swap(_read,rhs._read);

	std::swap(_write,rhs._write);
}

void Buffer::reserve(size_t size)
{
	_data.reserve(size);
}

char * Buffer::data()
{
	return _data.data();
}

const char * Buffer::data() const
{
	return data();
}

char * Buffer::read_data()
{
	return data() + _read;
}

const char * Buffer::read_data() const
{
	return read_data();
}

char * Buffer::write_data()
{
	return data() + _write;
}

const char * Buffer::write_data() const
{
	return write_data();
}

size_t Buffer::readable_size() const
{
	return _write - _read;
}

size_t Buffer::writeable_size() const
{
	return _data.capacity() - _write;
}

size_t Buffer::size()const
{
	return _data.size();
}

void Buffer::produce(size_t size)
{
	_write += size;
}

void Buffer::consume(size_t size)
{
	_read += size;
}

void Buffer::clear()
{
	_read = 0;

	_write = 0;
}

void Buffer::reset(size_t size)
{
	clear();

	if(size < _data.capacity())
	{
		_data.clear();
	}

	_data.reserve(size);

}


} /* namespace zeus */
